<!-- 量表详细信息-->
<template>
  <a-card :bordered="false" class="card-area">


    <!-- 搜索区域 -->
    <a-form layout="horizontal">
      <a-row>
        <a-col :md="24" :sm="24">
          <a-form-item label="量表名称" :labelCol="{ span: 4 }" :wrapperCol="{ span: 18, offset: 2 }">
            <a-input v-model="checkDetailInfo.name" />
          </a-form-item>
        </a-col>       
      </a-row>
      <a-row>      
        <a-col :md="24" :sm="24">
          <a-form-item label="量表编码" :labelCol="{ span: 4 }" :wrapperCol="{ span: 18, offset: 2 }">
            <a-input v-model="checkDetailInfo.code" />
          </a-form-item>
        </a-col>
      </a-row>

      <a-row>
        <a-col :md="24" :sm="24">
          <a-form-item label="量表指导" :labelCol="{ span: 4 }" :wrapperCol="{ span: 18, offset: 2 }">
            <textarea name="t1" rows="3" cols="200" v-model="checkDetailInfo.guide"></textarea>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="24" :sm="24">
          <a-form-item label="量表说明" :labelCol="{ span: 4 }" :wrapperCol="{ span: 18, offset: 2 }">
            <textarea name="t1" rows="3" cols="200" v-model="checkDetailInfo.description"></textarea>
          </a-form-item>
        </a-col>
      </a-row>

      <a-row>
        <a-col :md="24" :sm="24">
          <a-form-item label="量表问题列表">
          </a-form-item>
        </a-col>
      </a-row>

    </a-form>


    <!-- 表格区域 -->
    <a-table ref="TableInfo" :columns="columns" :rowKey="record => record.id" :dataSource="checkDetailInfo.questionList"
      :loading="loading" :scroll="{ x: 900 }">

      <template slot="operation" slot-scope="text, record">
        <a-icon type="eye" theme="twoTone" twoToneColor="#42b983" @click="view(record)" title="查看选项"></a-icon>
      </template>

      <template slot="question" slot-scope="text, record">
        <img v-if="record.tableId <= 3" :src="'/static/table_img' + record.question" />
        <span v-if="record.tableId > 3">{{ text }}</span>
      </template>

    </a-table>

    <!-- 量表问题选项查看 -->
    <question-detail :detailData="detail.data" :detailVisiable="detail.visiable" @close="handleClose">
    </question-detail>

  </a-card>
</template>

<script>
import QuestionDetail from './QuestionDetail'
import RangeDate from '@/components/datetime/RangeDate'

export default {
  name: 'CheckTableDetail',
  components: { RangeDate, QuestionDetail },
  data() {
    return {
      detail: {
        visiable: false,
        data: {}
      },
      checkDetailInfo: {},
      loading: false,
      pagination: {
        pageSizeOptions: ['10', '20', '30', '40', '100'],
        defaultCurrent: 1,
        defaultPageSize: 10,
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: (total, range) => `显示 ${range[0]} ~ ${range[1]} 条记录，共 ${total} 条记录`
      }
    }
  },
  computed: {
    columns() {
      return [{
        title: '序号',
        dataIndex: 'sort'
      }, {
        title: '问题',
        dataIndex: 'question',
        scopedSlots: { customRender: 'question' }
      }, {
        title: '题目选项1',
        dataIndex: 'titleOne'
      }, {
        title: '题目选项2',
        dataIndex: 'titleTwo'
      }, {
        title: '创建时间',
        dataIndex: 'createTime'
      }, {
        title: '选项详情',
        dataIndex: 'operation',
        scopedSlots: { customRender: 'operation' }
      }]
    }
  },
  mounted() {
    this.fetch()
  },
  methods: {

    view(record) {
      this.detail.data = record
      this.detail.visiable = true
    },

    handleClose() {
      this.detail.visiable = false
    },

    reset() {
      // 清空部门树选择
      this.$refs.deptTree.reset()
      this.fetch()
    },

    fetch() {
      this.loading = true
      this.$get('CheckTable/view/' + this.$route.params.id).then((r) => {
        this.checkDetailInfo = r.data.data
        this.loading = false
      })
    }
  }
}
</script>
<style lang="less" scoped>
@import "../../../static/less/Common";
</style>
